package com.jbm.jbmsupplier.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.activity.address.view.ShowImageViews;
import com.jbm.jbmsupplier.utlis.MyDispuPic;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by 家帮忙 on 2017/4/21.
 */

public class Gridviewlayouts extends RecyclerView.Adapter<Gridviewlayouts.MyViewHolders> {

    Context context;
    ArrayList<HashMap<String,String>> array;
  ArrayList<MyDispuPic> arraydis;
    public Gridviewlayouts(Context context, ArrayList<HashMap<String,String>> array) {
        this.context = context;
        this.array = array;
        arraydis=new ArrayList<>();
    }

    @Override
    public MyViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolders(View.inflate(context, R.layout.gridviewlayout_lz,null));
    }

    @Override
    public int getItemCount() {



        return array.size();
    }

    @Override
    public void onBindViewHolder(final MyViewHolders holder, final int position) {

//        if (array.get(position).get("type").equals("pic")){


                Picasso.with(context).load(array.get(position).get("pic")).resize(135,135).into(holder.grid);
             holder.grid.setTag(position);











//        }else  if (array.get(position).get("type").equals("audio")){
//            holder.grid.setTag(position);
//            Picasso.with(context).load(R.mipmap.yuyinbofang).resize(135,135).into(holder.grid);
//        }else  if (array.get(position).get("type").equals("video")){
//            holder. grid.setTag(position);
//            holder.videobofang.setVisibility(View.VISIBLE);
//            Picasso.with(context).load(new File(array.get(Integer.parseInt(holder.grid.getTag()+"")).get("pic"))).resize(135,135).into(holder.grid);
//        }
//        holder.videobofang.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                context.startActivity(new Intent(context, VideoCamer.class).putExtra("url",array.get(Integer.parseInt(holder.grid.getTag()+"")).get("pic")));
//            }
//        });
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if (array.get(position).get("type").equals("pic")) {
                    context.startActivity(new Intent(context, ShowImageViews.class).putExtra("image", array.get(Integer.parseInt(holder.grid.getTag() + "")).get("pic")));
//                }else if (array.get(position).get("type").equals("video")){
//                    playMusic(array.get(Integer.parseInt(holder.grid.getTag() + "")).get("path"));

//                }
            }
        });
    }

    class MyViewHolders extends RecyclerView.ViewHolder{
        ImageView grid,videobofang;
        TextView textstatic;
        public MyViewHolders(View itemView) {
            super(itemView);
            grid=(ImageView) itemView.findViewById(R.id.gridimage);
            videobofang=(ImageView) itemView.findViewById(R.id.videobofang);
            textstatic= (TextView) itemView.findViewById(R.id.textstatic);
        }
    }

}
